<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  	<link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap.min.css" />
		<link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap-responsive.min.css" />
		<link rel="stylesheet" href="<%=request.getContextPath() %>/css/matrix-style.css" />
		<link rel="stylesheet" href="<%=request.getContextPath() %>/css/matrix-media.css" />
  	<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.min.js"></script> 
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.uniform.js"></script> 
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/select2.min.js"></script> 
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/matrix.form_common.js"></script> 
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery/plugin/jquery.form.min.js"></script>
		<link href="<%=request.getContextPath() %>/font-awesome/css/font-awesome.css" rel="stylesheet" />
		<link rel="stylesheet"  href="<%=request.getContextPath() %>/css/select2.css" />
		<link rel="stylesheet" href="<%=request.getContextPath() %>/css/uniform.css" />
  	<script type="text/javascript" src="<%=request.getContextPath() %>/js/lhgdialog/dialogUtil.js"></script>
  	<script type="text/javascript" src="<%=request.getContextPath() %>/js/lhgdialog/dialogUtilNew.js"></script>
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/lhgdialog/lhgdialog.min.js?skin=iblue"></script>
		<script type="text/javascript">
			// 保存问卷绑定
			function saveSurveySend(){
					if(jQuery("#survey_id").val()==""){
						alert("请指定问卷");
						return false;
					}
					
	    		if(tab == "1"){
						if(jQuery("#company_id").val()==""){
							alert("请选择一个单位");
							return false;
						}
	    		}
				  jQuery(".btn").attr("disabled", "disabled");
					jQuery("#surveySendForm").ajaxSubmit({
						url:"<%=request.getContextPath() %>/survey/send/saveSurveySend.html?tab="+tab,
						type:"post",
						dataType:"json",
						success:function(data){
							if(data !==""){
								alertSuccess(data,refersh());
							}else{
								closeDialog();
							}
						}
					});
			}

			function refersh(){
				var api = frameElement.api;
				var W = api.opener;
				jQuery("#searchButton2",W.document).click();
				closeDialog();
			}
			// 保存问卷绑定并发放
			function saveSendSurveySend(){
				if(zfValidate.validate()){
					jQuery("#surveySendForm").ajaxSubmit({
						url:"<%=request.getContextPath() %>/survey/send/saveSurveySend.html",
						type:"post",
						dataType:"json",
						success:function(data){
							alert(data,function(){
								
								//问卷发放面页
								//----------------
							});
						}
					});
				}
			}

		  var tab = "1";
			jQuery(function(){

					jQuery("#tjxx1").show();
					jQuery("#tjxx2").hide();
					jQuery("#preview").bind("click",function(){
						var survey_id = jQuery("#survey_id").val();
						if(survey_id==""){ alert("请先选择问卷"); return false;}
						//预览问卷
						//-----------------------
						showDialog("预览问卷",1000,550,"<%=request.getContextPath() %>/wjgl/survey/viewSurvey.html?id="+survey_id);
					});
					
		    	jQuery("#tab_1").bind("click",function(){
		    		tab = "1";
						jQuery("#tjxx1").show();
						jQuery("#tjxx2").hide();
			    	
		    	});

		    	jQuery("#tab_2").bind("click",function(){
			    	tab = "2";
						jQuery("#tjxx1").hide();
						jQuery("#tjxx2").show();
		    	});
				//切换单位
				jQuery("#company_id").change(function(){
					jQuery("#tjxx1").html("需发送问卷：13333份 【自评44份；上级：55份；平级：666份；下级：666份】");
				});

				//切换被评估人
				jQuery("#assess_user_id").change(function(){
					jQuery("#tjxx2").html("需发送问卷：1444份 【自评44份；上级：55份；平级：666份；下级：666份】");
				});
				
				//jQuery("#assessUser").bind("change",function(){
				//	jQuery("#tjxx").html("需发送问卷：1444份 【自评44份；上级：55份；平级：666份；下级：666份】");
				//}
			});
		</script>
  </head>
  <body>
		<div class="widget-box">
       <div class="widget-title"> <span class="icon"> <i class="icon-align-justify"></i> </span>
         <h5>问卷绑定</h5>
       </div>
	      <div class="widget-title">
	        <ul class="nav nav-tabs">
	          <li class="active"><a data-toggle="tab" href="#tab1" id="tab_1">按单位绑定</a></li>
	          <li><a data-toggle="tab" href="#tab2" id="tab_2">按个人绑定</a></li>
	        </ul>
	      </div>
       <form action="/survey/send/saveSurveySend.html" method="post" class="form-horizontal" id="surveySendForm">
      	 <div class="widget-content nopadding tab-content">
           <div class="control-group">
             <label class="control-label"><span style="color:red;">*</span>指定问卷</label>
             <div class="controls">
	              <select name="survey_id" id="survey_id">
	              	 <option value="" selected></option>
	              	 <s:iterator value="surveyList" id="s" >
	              		<option value="<s:property value="#s.id"/>"><s:property value="#s.name"/></option>
	              	</s:iterator>
	             </select>
	             <input type="button" class="btn btn-mini btn-info" value="预览" id="preview">
             </div>
           </div>
          <div id="tab1" class="tab-pane active">
           <div class="control-group" id="dwmc">
             <label class="control-label"><span style="color:red;">*</span>单位名称</label>
             <div class="controls">
	              <select name="company_id" id="company_id">
	              	 <option value="" selected></option>
	              	<s:if test="companyList!=null">
		              	 <s:iterator value="companyList" id="s" >
		              		<option value="<s:property value="#s.company_id"/>"><s:property value="#s.company_name"/></option>
		              	</s:iterator>
	              	</s:if>
	              </select>
	              <span class="help-block">可模糊查询已维护的单位。</span>
             </div>
           </div>
          </div>
          <div id="tab2" class="tab-pane">
           <div class="control-group" id="yhxm">
             <label class="control-label"><span style="color:red;">*</span>被评估人</label>
              <div class="controls">
	              <select multiple id="assess_user_id" name="assess_user_id" >
	              	<s:if test="relationList!=null">
		              	<s:iterator value="relationList" id="s" >
		              		<option value="<s:property value="#s.user_id"/>"
		              		<s:if test="model.superior.indexOf(#s.user_id)!=-1">selected</s:if>	              		
		              		><s:property value="#s.user_info"/></option>
		              	</s:iterator>
	              	</s:if>
	              </select>
	              <span class="help-block">可多选。</span>
             </div>
           </div>
         </div>
         <!--  
           <div class="control-group">
             <label class="control-label">绑定统计信息</label>
             <div class="controls">
             		<span class="help-block" id="tjxx1">需发送问卷：139份 【自评40份；上级：30份；平级：30份；下级：39份】</span>
             		<span class="help-block" id="tjxx2">需发送问卷：139份 【自评40份；上级：30份；平级：30份；下级：39份】</span>
             </div>
           </div>
          -->
           <div class="modal-footer">
           	<div style="float:left;">"<span style="color:red;">*</span>"为必填项。</div>
           	<a href="#" class="btn" data-dismiss="modal" onclick="closeDialog();" >关闭</a>
           	<a href="#" id="add-event-submit" class="btn btn-primary" onclick="saveSurveySend();" >保存</a>
           	<!--  
           		<a href="#" id="add-event-submit" class="btn btn-success" onclick="saveSendSurveySend();" >直接发放问卷</a>
           	-->
           </div>
       </div>
      </form>
     </div>
  </body>
</html>
